package com.beta.cust.bind.datasync.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.beta.cust.bind.datasync.constant.BusinessConstant;
import com.beta.cust.bind.datasync.mapper.CustInfoMapper;
import com.beta.cust.bind.datasync.mapper.entity.CustInfo;
import com.beta.cust.bind.datasync.service.ICustInfoService;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 * 客户信息表 服务实现类
 * </p>
 *
 * @author pcc
 * @since 2024-03-12
 */
@Service
public class CustInfoServiceImpl extends ServiceImpl<CustInfoMapper, CustInfo> implements ICustInfoService {

    @Override
    public List<CustInfo> selectByExternalUserList(List<String> externalUserList) {
        if(CollectionUtils.isEmpty(externalUserList)){
            return new ArrayList<>();
        }
        return this.baseMapper.selectList(new LambdaQueryWrapper<CustInfo>()
                .in(CustInfo::getExternalUserid, externalUserList)
                .eq(CustInfo::getDelFlag,BusinessConstant.IS_NOT_DEL_FLAG));
    }

    @Override
    public void updateTimeBatchByList(List<CustInfo> custInfoList) {
        if(CollectionUtils.isEmpty(custInfoList)){
            return;
        }
        List<String> externalUserIdList = custInfoList.stream().map(CustInfo::getExternalUserid).collect(Collectors.toList());
        CustInfo updateEntity = new CustInfo();
        updateEntity.setUpdateTime(custInfoList.get(0).getUpdateTime());
        this.baseMapper.update(updateEntity,new LambdaQueryWrapper<CustInfo>()
                .in(CustInfo::getExternalUserid,externalUserIdList)
                .eq(CustInfo::getDelFlag,BusinessConstant.IS_NOT_DEL_FLAG));
    }
}
